package view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;





import javax.swing.JPasswordField;
import javax.swing.JTextPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.JLabel;
import javax.swing.SwingConstants;
/**
 * this class is Graphic user interface of login, which extends AbstractGUI
 * @author jacob
 *
 */
public class LoginGui1 extends JFrame  {
	/**all buttons labels and text fields*/
	private JPanel contentPane;
	private JButton loginBut = null;
	private JButton fpBut = null;
	private JLabel lblUserName = null;
    private JLabel lblwarningMessage = null;
    private JLabel lblLoginshow = null;

	private JLabel lblPassword = null;
	private JTextField textField;
	private JPasswordField passfield;
	private Font myFont,loginlb;
	/**
	 * login gui Constructor
	 * this constructor add all the Label, Button,TextField on the Frame
	 */
	public LoginGui1() {
		myFont = new Font("Serif",Font.BOLD,17);
		loginlb = new  Font("Stencil", Font.ITALIC, 30);
		getContentPane().setLayout(null);
		getContentPane().add(getLogin());
		getContentPane().add(getFp());
		getContentPane().add(getLblwarningMessage());
		getContentPane().add(getLblUserName());
		getContentPane().add(getLblPassword());
		getContentPane().add(getTextFieldUser());
		getContentPane().add(getTextFieldPass());
		getContentPane().add(getLblLog());
		getContentPane().setBackground(Color.CYAN);
		this.setTitle("ccrm/Login");
		this.setBounds(500, 200, 325, 325);
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.setVisible(true);
		this.setResizable(false);
	
	}
	
	/*****************************************Getters and Setters of Label, Button,TextField *****************************/
	public JLabel getLblwarningMessage() {
		if(lblwarningMessage == null){
			lblwarningMessage = new JLabel("user name or password is wrong");
			lblwarningMessage.setForeground(Color.RED);
			lblwarningMessage.setBounds(10, 165, 200, 30);
			lblwarningMessage.setVisible(false);
		}
		return lblwarningMessage;
	}
	public void setWarningMessageVisibleTrue() {
		lblwarningMessage.setVisible(true);	
	}
	
	public void setWarningMessageVisibleTrue(String st) {
		lblwarningMessage.setText(st);
		lblwarningMessage.setForeground(Color.RED);
		lblwarningMessage.setBounds(10, 165, 245, 30);
		lblwarningMessage.setVisible(true);	
		
	}

	public JButton getLogin() {
		
		if(loginBut == null ) {
			loginBut = new JButton("Login");
			loginBut.setBounds(120, 220, 100, 30);
		}
		return loginBut;
	}

	
	public JButton getFp() {
		if(fpBut == null){
			fpBut = new JButton("forgot password");
		fpBut.setBounds(200, 200, 140, 20);
		}
		fpBut.setVisible(false);
		return fpBut;
	}
	
	public JLabel getLblUserName() {
		if(lblUserName == null) {
			lblUserName = new JLabel("user name:");
			lblUserName.setBounds(15, 70, 90, 20);
			lblUserName.setFont(myFont);
		}
		return lblUserName;
	}
	
	public JLabel getLblLog() {
		if(lblLoginshow == null) {
			lblLoginshow = new JLabel("Login");
			lblLoginshow.setBounds(100, 7, 110, 60);
			lblLoginshow.setHorizontalAlignment(SwingConstants.CENTER);
			lblLoginshow.setFont(loginlb);
		}
		return lblLoginshow;
	}

	public JLabel getLblPassword() {
		if(lblPassword == null){
			lblPassword = new JLabel("password :");
			lblPassword.setBounds(15, 120, 90, 20);
			lblPassword.setFont(myFont);
		}
		return lblPassword;
	}

	public JTextField getTextFieldUser() {
		if(textField == null) {
			textField = new JTextField();
			textField.setBounds(105, 73, 130, 20);
			textField.setColumns(10);
		}
		return textField;
	}

	public JPasswordField getTextFieldPass() {
		if(passfield == null) {
			passfield = new JPasswordField();
			passfield.setBounds(105, 123, 130, 20);
			passfield.setColumns(10);
		}
		return passfield;
	}
	public void ClearText(){
		textField.setText("");
		passfield.setText("");
	}
	/****************************************get the texts from Textfields******************************/
	public String getTextUserName() {
		return textField.getText();
	}
	
	public String getTextPassword() {
		
		String str = new String(passfield.getPassword());
		return str;
	}
	/**
	 * add to Login button Action Listener
	 * @param listener
	 */
	public void addLoginActionListener(ActionListener listener){
		loginBut.addActionListener(listener);
	}
	
	public void addporgotPasswordActionListener(ActionListener listener){
		fpBut.addActionListener(listener);
	}
/**
 * set warning massage false
 */

	public void undisplayWarningMessage() {
		lblwarningMessage.setVisible(false);
		
	}
	
	

}
